const app = getApp();
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var user = require('../../../services/user.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    current_page: 1,
    orderList:[],
    tabNav: {
      list:[],
      selectedId:99
    },
    last_page:false,
    per_page:15,
    total:0,

    more_type:"more",
    more_str:"下拉加载更多。。。"
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getOrderList();
  },
  getOrderList: function () {
    let that = this;

    util.request(api.OrderList, { status: this.data.tabNav.selectedId, page: this.data.current_page }).then(res => {      
      if (res.code === 200) {
        var oldorderList = that.data.orderList
        var neworderList = oldorderList.concat(res.data.orderList.data)
        that.setData({
          orderList: neworderList,
          tabNav: res.data.tabNav,
          current_page: res.data.orderList.current_page,
          last_page: res.data.orderList.last_page,
          per_page: res.data.orderList.per_page,
          total: res.data.orderList.total     
        });
        if (res.data.orderList.last_page == res.data.orderList.current_page){
          that.setData({ more_type: "nomore", more_str: "没有更多了"})
        }else{
          that.setData({ more_type: "hasmore", more_str: "下拉加载更多。。。" })
        }
        // console.log(res.data)
      }
      wx.hideLoading();
    }).catch(() => {
      // wx.navigateTo({
      //   url: '/pages/auth/login/login',
      // })
      wx.hideLoading();
    });
    
  },

  tabChange:function(e){
    this.setData({
      'tabNav.selectedId':e.detail,
      current_page: 1,
      orderList: [],
      last_page: false,
      per_page: 15,
      total: 0
    })
    this.getOrderList();
  },
  payOrder:function(){

  },
  cancelOrder:function(){

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.setData({ current_page: parseInt(this.data.current_page) + 1})
    wx.showLoading({
      title: '加载中。。。',
    })
    this.getOrderList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})